package Mangos::DB;

use strict;
use warnings;

use base 'Rose::DB'; 
use YAML;
use Data::Dumper;

my %db_config = %{YAML::LoadFile('/var/www/vhosts/default/htdocs/wowperl/config.yml')};

__PACKAGE__->use_private_registry;

my $realm_counter = 1;
foreach my $realm (@{$db_config{realms}}) {
   # register the mangos databases
   __PACKAGE__->register_db(
      type     => 'mangos',
      domain   => sprintf("realm%i",$realm_counter),
      driver   => $db_config{db_type},
      database => $realm->{mangos_db_name},
      host     => $realm->{address},
      username => $realm->{mangos_db_user},
      password => $realm->{mangos_db_pass}
   );

   # register the character database
   __PACKAGE__->register_db(
      type     => 'characters',
      domain   => sprintf("realm%i",$realm_counter),
      driver   => $db_config{db_type},
      database => $realm->{char_db_name},
      host     => $realm->{address},
      username => $realm->{mangos_db_user},
      password => $realm->{mangos_db_pass}
   );

   $realm_counter++;
}

# register the lonely realmd
__PACKAGE__->register_db(
   type     => 'realmd',
   domain   => 'realm1',
   driver   => $db_config{db_type},
   database => $db_config{reamld_db_name},
   host     => $db_config{realmd_address},
   username => $db_config{realmd_user},
   password => $db_config{realmd_pass}
);

__PACKAGE__->default_domain('realm1');

1;
 
